#include "magellan/magellan.hpp"
#include <iostream>

USING_MAGELLAN_NS
USING_HAMCREST_NS

namespace
{
    int i = 0 ; 
}

FIXTURE(RValueTest)
{
    struct Tmp
    {
        Tmp(int x):x(x)
        {
        }
        Tmp(const Tmp& t)
        {
            i++;
            std::cout<<"copy"<<std::endl;
        }
        Tmp(Tmp&& t)
        {
            
        }
        int x;
    };

    Tmp getTmp()
    {
        Tmp t(3);
        return t;
    }

    SETUP()
    {
        i = 0;
    }

    TEST("should copy once when use rvalue ref")
    {
        Tmp&& t = getTmp();
        t.x = 4;
        Tmp t2 = t;
        ASSERT_THAT(i, is(0));
        ASSERT_THAT(t.x, is(4));
    }

    TEST("should copy twice not use rvalue ref")
    {
        Tmp t1(5);
        t1 = getTmp();
        Tmp t2 = t1;
        ASSERT_THAT(i, is(1));
    }
};
